<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <include file="Public:common_file" />
    <meta name="description" content="{$info.description}">
    <meta name="keywords" content="{$info.keywords}">
    <title>{$info.title}-用户注册</title>
    <style type="text/css">
    	.login{
    		width:100%; margin-top:50px; padding:10px 0; 
    	}
    	.login input[type='text']{
    		margin:5px 0; border-radius:0px; border:none; border-bottom:1px solid #d8d8d8;
    		height:45px;
    	}
    	.login input[type='password']{
    		margin:5px 0; border-radius:0px; border:none; border-bottom:1px solid #d8d8d8;
    		height:45px;
    	}
    	.login input[type='number']{
    		margin:5px 0; border-radius:0px; border:none; border-bottom:1px solid #d8d8d8;
    		height:45px; width:60%; float:left;
    	}
    	.login img{
    		width:40%; float:right;margin:5px 0; height:45px;
    	}
    	.login div{
    		width:40%; float:right;    margin: 7px 0;
		    height: 42px;
		    line-height: 29px;
    	}
    	.login button{
    		width:90%; margin:5px 5%;
    	}
    	.login a{
    		width:90%; margin:5px 5%;
    	}
    </style>
</head>
<body>

	<div class="head" style="background-color:#f23030;">
        <div class="left" onclick="back()">
            <i class="icon-chevron-left"></i>
        </div>
        <div class="center">
            <p><i class="icon-user"></i> 用户注册</p>
        </div>
        <div class="right">
            
        </div>
    </div>

    <div class="login">
    	<form method="post" action="{:U('Login/do_reg')}" onsubmit="return check();">
    		<input type="text" id="mobile" name="mobile" class="form-control" placeholder="请输入手机号">
	    	<input type="password" id="pwd1" name="pwd" class="form-control" placeholder="请输入6位以上密码">
	    	<input type="password" id="pwd2" name="pwd2" class="form-control" placeholder="请重复输入密码">
	    	<input type="number" name="code" id="code" class="form-control" placeholder="请输入验证码">
	    	<img src="{:U('Login/code')}" onclick="change_code()" id="cimg">
	    	<input type="number" name="sms" id="sms" class="form-control" placeholder="请获取短信验证码">
	    	<div class="btn btn-primary" onclick="get_code()">获取验证码</div>
	    	<button class="btn btn-primary" type="submit">注册</button>
	    	<a class="btn btn-default" href="{:U('Login/index')}">已有账号？立即登录</a>
    	</form>
    	
    </div>
    

	<include file="Public:foot" />

    <script type="text/javascript">
    	function get_code(){
		    var mobile = $('#mobile').val();
		    if(!(/^1[3|4|5|7|8]{1}\d{9}$/.test(mobile))){ 
		        alert("请输入正确手机号！"); 
		        $('#mobile').focus();
		        change_code();
		        return false;
		    }
		    var pwd1 = $('#pwd1').val();
		    var pwd2 = $('#pwd2').val();
		    if (pwd1.length < 6) {
		    	alert("密码请在6位以上！"); 
		    	$('#pwd1').focus();
		    	change_code();
		    	return false;
		    }
		    if (pwd1!=pwd2) {
		    	alert("两次密码输入不一致！"); 
		    	$('#pwd1').focus();
		    	change_code();
		    	return false;
		    }

		    var code = $('#code').val();
		    if (!(/^\d{4}$/.test(code))) {
		    	alert("请输入正确的验证码！");
		    	$('#code').focus();
		    	change_code();
		    	return false;
		    }
			$.post("{:U('Login/get_sms')}", {mobile:mobile,code:code},
			function(data){
				if (data.success == 0) {
					alert(data.res);
					change_code();
				}else{
					hover_in('验证码已下发，稍后系统会帮您自动填充...');
                    setTimeout("set_sms()",3000);
				}
			}, "json");

    	}

        function set_sms(){
            var rand = ran(100000,999999);
            $('#sms').val(rand);
            hover_out();
        }

        function ran(n,m){
            var l = m-n;
            var num = Math.random()*l + n;
            num = parseInt(num, 10);
            return num;
        }

    	function change_code(){
    		$('#cimg').attr('src','{:U('Login/code')}?nocache='+ new Date().getTime()); 
    	}

        function check(){
            var mobile = $('#mobile').val();
            if(!(/^1[3|4|5|7|8]{1}\d{9}$/.test(mobile))){ 
                alert("请输入正确手机号！"); 
                $('#mobile').focus();
                return false;
            }
            var pwd1 = $('#pwd1').val();
            var pwd2 = $('#pwd2').val();
            if (pwd1.length < 6) {
                alert("密码请在6位以上！"); 
                $('#pwd1').focus();
                return false;
            }
            if (pwd1!=pwd2) {
                alert("两次密码输入不一致！"); 
                $('#pwd1').focus();
                return false;
            }

            var sms = $('#sms').val();
            if (!(/^\d{6}$/.test(sms))) {
                alert("请输入正确的短信验证码！");
                $('#sms').focus();
                return false;
            }

            return true;
        }

        imgload();
    </script>
	
</body>
</html>